package com.example.administrator.myproject.home

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast

import com.example.administrator.myproject.R

import cn.bmob.v3.BmobQuery
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.FindListener
import com.example.administrator.myproject.bean.BobmBean

class HomeFragment : Fragment() {
    private var recyclerView: RecyclerView? = null
    private var adapter: HomeAdapter? = null

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val view = inflater.inflate(R.layout.home_view, container, false)
        recyclerView = view.findViewById(R.id.home_rv)
        recyclerView!!.layoutManager = LinearLayoutManager(activity)
//        adapter = HomeAdapter(activity)
        recyclerView!!.adapter = adapter
        val bmobQuery = BmobQuery<BobmBean>()
        bmobQuery.findObjects(object : FindListener<BobmBean>() {
            override fun done(list: List<BobmBean>, e: BmobException?) {
                if (e == null) {
                    adapter!!.setData(list)
                } else {
                    Toast.makeText(activity, "查询失败", Toast.LENGTH_SHORT).show()
                }
            }
        })
        return view
    }
}
